package com.haidong.component;

import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;

public class UserIndexFrame extends JFrame {
    public UserIndexFrame(String title,Integer userId,String userName) throws HeadlessException {
        super(title);
        setBounds(200,200,600,400);
        addWindowListener(new WindowAdapter() {
            @Override
            public void windowClosing(WindowEvent e) {
                System.exit(0);
            }
        });
        setLayout(new BorderLayout());

        JPanel up = new JPanel();
        JLabel label = new JLabel("欢迎使用单位房产管理系统,欢迎用户" + userName + ",您的id编号是" + userId);
        up.add(label);

        JPanel left = new JPanel(new GridLayout(4,1));
        JButton house = new JButton("房子管理");
        JButton worker = new JButton("员工管理");
        JButton dept = new JButton("物业费用");
        JButton help = new JButton("帮助");
        left.add(house);
        left.add(worker);
        left.add(dept);
        left.add(help);

        //右下卡片布局
        CardLayout cardLayout = new CardLayout();
        JPanel center = new JPanel(cardLayout);
        //房子管理界面,默认显示查找房子信息,显示所有的房子信息
        JPanel card2 = MyHousePanel.select();
        //员工管理界面
        JPanel card3 = MyWorkerPanel.select();
        //物业费管理界面
        JPanel card4 = CostPanel.select();
        //帮助界面
        JPanel card5 = new HelpPanel();
        //监听大按钮切换页面
        ActionListener listener = new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                String command = e.getActionCommand();
                switch (command){
                    case "房子管理":
                        cardLayout.show(center,"房子管理");
                        break;
                    case "员工管理":
                        cardLayout.show(center,"员工管理");
                        break;
                    case "物业费用":
                        cardLayout.show(center,"物业费用");
                        break;
                    case "帮助":
                        cardLayout.show(center,"帮助");
                        break;
                }
            }
        };
        //卡片导入主panel
        center.add("房子管理",card2);
        center.add("员工管理",card3);
        center.add("物业费用",card4);
        center.add("帮助",card5);
        //给左侧按钮加监听器
        house.addActionListener(listener);
        worker.addActionListener(listener);
        dept.addActionListener(listener);
        help.addActionListener(listener);
        add(up,BorderLayout.NORTH);
        add(left,BorderLayout.WEST);
        add(center,BorderLayout.CENTER);
        setExtendedState(javax.swing.JFrame.MAXIMIZED_BOTH);

        setVisible(true);
    }
}
